﻿@using Grand.Business.Core.Interfaces.Common.Localization
@inject ILanguageService languageService
@inject IWorkContextAccessor workContextAccessor
@{
    var availableLanguages = (await languageService.GetAllLanguages(storeId: workContextAccessor.WorkContext.CurrentStore.Id))
        .Select(x => new LanguageModel
        {
            Id = x.Id,
            Name = x.Name,
            Rtl = x.Rtl,
            LanguageCulture = x.LanguageCulture,
            UniqueSeoCode = x.UniqueSeoCode
        }).ToList();

    var returnurl = Context?.Request?.GetEncodedPathAndQuery();
    if (availableLanguages.Count > 1)
    {
        <div>
            <b-dropdown class="mr-2" text="@availableLanguages.FirstOrDefault(x => x.Id == workContextAccessor.WorkContext.WorkingLanguage.Id)?.Name">
                @foreach (var lang in availableLanguages)
                {
                    var className = lang.Id == workContextAccessor.WorkContext.WorkingLanguage.Id ? "active" : "";
                    <b-dropdown-item class="@className" href="@Url.RouteUrl("ChangeLanguage", new { langcode = lang.UniqueSeoCode, returnurl })">
                        @lang.Name
                    </b-dropdown-item>
                }
            </b-dropdown>
        </div>
    }
}